{extend name="adminblue/base" /}
{block name="resources"/}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="color-red">*</span>楼层名称：</dt>
		<dd>
			<p><input id="block_name" type="text" style="width:300px;" value="{$block_info['block_name']}" class="input-common"></p>
			<p class="error">请输入楼层名称</p>
		</dd>
	</dl>
	<dl>
		<dt>简称：</dt>
		<dd>
			<p><input id="block_short_name" type="text" style="width:300px;" value="{$block_info['block_short_name']}" class="input-common"></p>
			<p class="error">请输入楼层简称</p>
		</dd>
	</dl>
	<dl>
		<dt>颜色风格：</dt>
		<dd>
			<input id="block_color" type="color" style="width:60px;height:25px;" value="{$block_info['block_color']}" class="input-common-color"/>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">*</span>排序：</dt>
		<dd>
			<p><input id="sort" type="text" style="width:300px;" value="{$block_info['sort']}" class="input-common"></p>
			<p class="error">请输入序号</p>
		</dd>
	</dl>
	<dl>
		<dt>是否显示：</dt>
		<dd>
			<p>
				<input id="is_display" type="checkbox" class="checkbox" {if condition="$block_info['is_display'] eq 1"} checked {/if}>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>推荐单图广告位：</dt>
		<dd>
			<p>
				<input id="recommend_ad_image_name" type="text" placeholder="请输入推荐单图广告位名称" value="{$block_info['recommend_ad_image_name']}" style="width:300px;" class="input-common"> 
				<select name="account" id="recommend_ad_image" style="width:300px;height:34px;" class="select-common">
					<option value="0">请选择推荐单图广告位</option>
					{volist name="recommend_ad_image_list" id="va1"}
						<option value="{$va1['ap_id']}" {if condition="$va1['ap_id'] eq $block_info['recommend_ad_image']"}selected{/if}>{$va1['ap_name']}</option>
					{/volist}
				</select>
			</p>
			<p class="error">推荐单图广告位名称不能为空</p>
		</dd>
	</dl>
	<dl>
		<dt>推荐多图广告位：</dt>
		<dd>
			<p>
				<input id="recommend_ad_images_name" type="text" placeholder="请输入推荐多图广告位名称"  value="{$block_info['recommend_ad_images_name']}"  style="width:300px;" class="input-common">
				<select name="account" class="form-control m-b select-common" id="recommend_ad_images" style="width:300px;height:34px;">
						<option value="0">请选择推荐多图广告位</option>
						{volist name="recommend_ad_images_list" id="va2"}
							<option value="{$va2['ap_id']}"  {if condition="$va2['ap_id'] eq $block_info['recommend_ad_images']"}selected{/if}>{$va2['ap_name']}</option>
						{/volist}
					</select>
			</p>
			<p class="error">推荐多图广告位名称不能为空</p>
		</dd>
	</dl>
	<dl>
		<dt>推荐幻灯片广告位：</dt>
		<dd>
			<p>
				<input id="recommend_ad_slide_name" type="text" placeholder="请输入推荐推荐幻灯片广告位广告位名称"  value="{$block_info['recommend_ad_slide_name']}"  style="width:300px;" class="input-common">
				<select name="account" class="form-control m-b select-common" id="recommend_ad_slide" style="width:300px;height:34px;" >
					<option value="0">请选择推荐幻灯片广告位</option>
					{volist name="recommend_ad_slide_list" id="va3"}
						<option value="{$va3['ap_id']}" {if condition="$va3['ap_id'] eq $block_info['recommend_ad_slide']"}selected{/if}>{$va3['ap_name']}</option>
					{/volist}
				</select>
			</p>
			<p class="error">推荐幻灯片广告位名称不能为空</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">*</span>推荐分类商品：</dt>
		<dd>
			<input class="input-common" id="recommend_goods_category_name_1" type="text" placeholder="请输入推荐分类商品别名" value="{$block_info['recommend_goods_category_name_1']}"  style="width:300px;">
			<span class="category_zero" style="display:inline-block;">
				分类： {notempty name="$block_info.goods_category_name_1"}{$block_info.goods_category_name_1}{/notempty}
				<input type="hidden" class="is_reset_category" dir="0" id="goods_category_id_1" value="{$block_info.recommend_goods_category_1}">
				<button class="btn" style="margin-left:10px;" onclick="resetGoodsCategory(this)">重新编辑</button>
			</span>
			<select name="account" class="form-control m-b hide category_first select-common" id="goods_category_first_1" style="width:145px;height:34px;">
				<option value="0">请选择一级分类</option>
				{volist name="goods_category_list" id="vo"}
					{if condition="$vo.level eq 1"}
						<option value="{$vo['category_id']}">{$vo['category_name']}</option>
					{/if}
				{/volist}
			</select>
			<select name="account" class="form-control m-b hide category_second select-common" id="goods_category_second_1" style="width:145px;height:34px;">
				<option value="0">请选择二级分类</option>
				{volist name="goods_category_list" id="vo"}
					{if condition="$vo.level eq 2"}
						<option value="{$vo['category_id']}" pid="{$vo['pid']}">{$vo['category_name']}</option>
					{/if}
				{/volist}
			</select>
			<select name="account" class="form-control m-b hide category_three select-common" id="goods_category_three_1"  style="width:145px;height:34px;">
				<option value="0">请选择三级分类</option>
				{volist name="goods_category_list" id="vo"}
					{if condition="$vo.level eq 3"}
						<option value="{$vo['category_id']}" pid="{$vo['pid']}">{$vo['category_name']}</option>
					{/if}
				{/volist}
			</select>
			
			<p class="error">推荐分类商品别名及分类选择不可为空</p>
		</dd>
		
	</dl>
	<dl>
		<dt><span class="color-red">*</span>推荐分类商品：</dt>
		<dd>
			<input class="input-common" id="recommend_goods_category_name_2" type="text" placeholder="请输入推荐分类商品别名"  value="{$block_info['recommend_goods_category_name_2']}"  style="width:300px;"> 
				<span class="category_zero" style="display:inline-block;">
					分类： {notempty name="$block_info.goods_category_name_2"}{$block_info.goods_category_name_2}{/notempty}
					<input type="hidden" class="is_reset_category" dir="0" id="goods_category_id_2" value="{$block_info.recommend_goods_category_2}">
					<button class="btn" style="margin-left:10px;" onclick="resetGoodsCategory(this)">重新编辑</button>
				</span>
				<select name="account" class="form-control m-b hide category_first select-common" id="goods_category_first_2" style="width:145px;height:34px;">
					<option value="0">请选择一级分类</option>
					{volist name="goods_category_list" id="vo"}
						{if condition="$vo.level eq 1"}
							<option value="{$vo['category_id']}">{$vo['category_name']}</option>
						{/if}
					{/volist}
				</select>
				<select name="account" class="form-control m-b hide category_second select-common" id="goods_category_second_2" style="width:145px;height:34px;">
					<option value="0">请选择二级分类</option>
					{volist name="goods_category_list" id="vo"}
						{if condition="$vo.level eq 2"}
							<option value="{$vo['category_id']}" pid="{$vo['pid']}">{$vo['category_name']}</option>
						{/if}
					{/volist}
				</select>
				<select name="account" class="form-control m-b hide category_three select-common" id="goods_category_three_2"  style="width:145px;height:34px;">
					<option value="0">请选择三级分类</option>
					{volist name="goods_category_list" id="vo"}
						{if condition="$vo.level eq 3"}
							<option value="{$vo['category_id']}" pid="{$vo['pid']}">{$vo['category_name']}</option>
						{/if}
					{/volist}
				</select>
				<p class="error">推荐分类商品别名及分类选择不可为空</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">*</span>推荐分类商品：</dt>
		<dd>
			<p>
				<input class="input-common" id="recommend_goods_category_name_3" type="text" placeholder="请输入推荐分类商品别名"  value="{$block_info['recommend_goods_category_name_3']}"  style="width:300px;"> 
				<span class="category_zero" style="display:inline-block;">
					分类： {notempty name="$block_info.goods_category_name_3"}{$block_info.goods_category_name_3}{/notempty}
					<input type="hidden" class="is_reset_category" dir="0" id="goods_category_id_3" value="{$block_info.recommend_goods_category_3}">
					<button class="btn" style="margin-left:10px;" onclick="resetGoodsCategory(this)">重新编辑</button>
				</span>
				<select name="account" class="form-control m-b hide category_first select-common" id="goods_category_first_3" style="width:145px;height:34px;">
					<option value="0">请选择一级分类</option>
					{volist name="goods_category_list" id="vo"}
						{if condition="$vo.level eq 1"}
							<option value="{$vo['category_id']}">{$vo['category_name']}</option>
						{/if}
					{/volist}
				</select>
				<select name="account" class="form-control m-b hide category_second select-common" id="goods_category_second_3" style="width:145px;height:34px;">
					<option value="0">请选择二级分类</option>
					{volist name="goods_category_list" id="vo"}
						{if condition="$vo.level eq 2"}
							<option value="{$vo['category_id']}" pid="{$vo['pid']}">{$vo['category_name']}</option>
						{/if}
					{/volist}
				</select>
				<select name="account" class="form-control m-b hide category_three select-common" id="goods_category_three_3"  style="width:145px;height:34px;">
					<option value="0">请选择三级分类</option>
					{volist name="goods_category_list" id="vo"}
						{if condition="$vo.level eq 3"}
							<option value="{$vo['category_id']}" pid="{$vo['pid']}">{$vo['category_name']}</option>
						{/if}
					{/volist}
				</select>
				<p class="error">推荐分类商品别名及分类选择不可为空</p>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>推荐品牌：</dt>
		<dd>
			<p>
				{volist name="goods_brand_list" id="vb"}
				<label class="checkbox-inline" style="display:inline-block;margin-right:5px;font-weight:normal;">
					<input type="checkbox" name="recommend_brands" value="{$vb['brand_id']}" style="margin-top:-2px;" {in name="$vb['brand_id']" value="$block_info['recommend_brands']"}checked{/in}> {$vb['brand_name']}
				</label>
				{/volist}
			</p>
		</dd>
	</dl>
	<dl>
		<dt>推荐商品分类：</dt>
		<dd>
			<p>
				{volist name="goods_category_list" id="vc"}
					<label class="checkbox-inline" style="display:inline-block;margin-right:5px;font-weight:normal;"> <input type="checkbox"
						name="recommend_categorys" value="{$vc['category_id']}" style="margin-top:-2px;"{in name="$vc['category_id']" value="$block_info['recommend_categorys']"}checked{/in}> {$vc['category_name']}
					</label>
				{/volist}
			</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="updateBlockAjax();">保存</button></dd>
	</dl>
</div>
<input type="hidden" id="block_id" value="{$block_info['block_id']}">
{/block}
{block name="script"}
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
//重新 选择商品分类
function resetGoodsCategory(event){
	$(event).prev(".is_reset_category").attr("dir", 1);
	$(event).parent().hide();
	$(event).parent().next(".category_first").show();
}

$(function(){
	$('.category_first').change(function(){
		var pid = $(this).val();
		var obj_category_second = $(this).parent().children('.category_second');
		obj_category_second.children('option:gt(0)').hide().parent().hide();
		var category_second_option_obj = obj_category_second.children('option[pid="'+pid+'"]')
		category_second_option_obj.show().parent().show();
		obj_category_second.val(0);
		obj_category_second.trigger('change');
	})
	$('.category_second').change(function(){
		var pid = $(this).val();
		var obj_category_three = $(this).parent().children('.category_three')
		obj_category_three.val(0);
		obj_category_three.children('option:gt(0)').hide().parent().hide();
		obj_category_three.children('option[pid="'+pid+'"]').show().parent().show();
	})
})

function updateBlockAjax() {
	var block_id = $("#block_id").val();
	var block_name = $("#block_name").val();
	var block_short_name = $("#block_short_name").val();
	var block_color = $("#block_color").val();
	var sort = $("#sort").val();
	if($("#is_display").prop("checked")){
		var is_display = 1;
	}else{
		var is_display = 0;
	}
	var recommend_ad_image_name = $("#recommend_ad_image_name").val();
	var recommend_ad_image = $("#recommend_ad_image").val();
	var recommend_ad_images_name = $("#recommend_ad_images_name").val();
	var recommend_ad_images = $("#recommend_ad_images").val();
	var recommend_ad_slide_name = $("#recommend_ad_slide_name").val();
	var recommend_ad_slide = $("#recommend_ad_slide").val();
	var recommend_brands = '';
	$("input[type='checkbox'][name='recommend_brands']:checked").each(function(){ 
		recommend_brands += $(this).val()+","; 
	});
	recommend_brands = recommend_brands.substring(0,recommend_brands.length-1);
	var recommend_categorys = '';
	$("input[type='checkbox'][name='recommend_categorys']:checked").each(function(){ 
		recommend_categorys += $(this).val()+","; 
	});
	recommend_categorys = recommend_categorys.substring(0,recommend_categorys.length-1);
	var recommend_goods_category_name_1 = $("#recommend_goods_category_name_1").val();
	var recommend_goods_category_name_2 = $("#recommend_goods_category_name_2").val();
	var recommend_goods_category_name_3 = $("#recommend_goods_category_name_3").val();
	if($("#goods_category_id_1").attr("dir") == 1){
		if($("#goods_category_three_1").val() > 0){
			var recommend_goods_category_1 = $("#goods_category_three_1").val();
		}else if($("#goods_category_second_1").val() > 0){
			var recommend_goods_category_1 = $("#goods_category_second_1").val();
		}else{
			var recommend_goods_category_1 = $("#goods_category_first_1").val();
		}
	}else{
		var recommend_goods_category_1 = $("#goods_category_id_1").val();
	}
	if($("#goods_category_id_2").attr("dir") == 1){
		if($("#goods_category_three_2").val() > 0){
			var recommend_goods_category_2 = $("#goods_category_three_2").val();
		}else if($("#goods_category_second_2").val() > 0){
			var recommend_goods_category_2 = $("#goods_category_second_2").val();
		}else{
			var recommend_goods_category_2 = $("#goods_category_first_2").val();
		}
	}else{
		var recommend_goods_category_2 = $("#goods_category_id_2").val();
	}
	if($("#goods_category_id_3").attr("dir") == 1){
		if($("#goods_category_three_3").val() > 0){
			var recommend_goods_category_3 = $("#goods_category_three_3").val();
		}else if($("#goods_category_second_3").val() > 0){
			var recommend_goods_category_3 = $("#goods_category_second_3").val();
		}else{
			var recommend_goods_category_3 = $("#goods_category_first_3").val();
		}
	}else{
		var recommend_goods_category_3 = $("#goods_category_id_3").val();
	}
	
	if(verify(block_name, recommend_ad_image_name, recommend_ad_image, recommend_ad_images_name, recommend_ad_images, recommend_ad_slide_name, recommend_ad_slide,
			recommend_goods_category_name_1, recommend_goods_category_1, recommend_goods_category_name_2, recommend_goods_category_2, recommend_goods_category_name_3, recommend_goods_category_3)){
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/system/updateblock')}",
			data : {
				'block_id' : block_id,
				'block_name' : block_name,
				'block_short_name' : block_short_name,
				'block_color' : block_color,
				'sort' : sort,
				'is_display' : is_display,
				'recommend_ad_image_name' : recommend_ad_image_name,
				'recommend_ad_image' : recommend_ad_image,
				'recommend_ad_images_name' : recommend_ad_images_name,
				'recommend_ad_images' : recommend_ad_images,
				'recommend_ad_slide_name' : recommend_ad_slide_name,
				'recommend_ad_slide' : recommend_ad_slide,
				'recommend_brands' : recommend_brands,
				'recommend_categorys' : recommend_categorys,
				'recommend_goods_category_name_1' : recommend_goods_category_name_1,
				'recommend_goods_category_1' : recommend_goods_category_1,
				'recommend_goods_category_name_2' : recommend_goods_category_name_2,
				'recommend_goods_category_2' : recommend_goods_category_2,
				'recommend_goods_category_name_3' : recommend_goods_category_name_3,
				'recommend_goods_category_3' : recommend_goods_category_3
			},
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', "编辑成功","{:__URL('ADMIN_MAIN/system/blocklist')}");
				}else{
					showMessage('error', "编辑失败");
				}
			}
		});
	}
}

function verify(
		block_name,
		recommend_ad_image_name, recommend_ad_image,
		recommend_ad_images_name, recommend_ad_images,
		recommend_ad_slide_name, recommend_ad_slide,
		recommend_goods_category_name_1, recommend_goods_category_1, 
		recommend_goods_category_name_2, recommend_goods_category_2, 
		recommend_goods_category_name_3, recommend_goods_category_3
		){
	if(block_name == ''){
		$("#block_name").parent().next().show();
		return false;
	}else{
		$(".error").hide();
	}
	if(recommend_ad_image > 0){
		if(recommend_ad_image_name == ''){
			$("#recommend_ad_image_name").parent().next().show();
			return false;
		}else{
			$(".error").hide();
		}	
	}
	if(recommend_ad_images > 0){
		if(recommend_ad_images_name == ''){
			$("#recommend_ad_images_name").parent().next().show();
			return false;
		}else{
			$(".error").hide();
		}
	}
	if(recommend_ad_slide > 0){
		if(recommend_ad_slide_name == ''){
			$("#recommend_ad_slide_name").parent().next().show();
			return false;
		}else{
			$(".error").hide();
		}
	}
	if(recommend_goods_category_name_1 == '' || recommend_goods_category_1 == 0){
		$("#recommend_goods_category_name_1").parent().children('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	if(recommend_goods_category_name_2 == '' || recommend_goods_category_2 == 0){
		$("#recommend_goods_category_name_2").parent().children('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	if(recommend_goods_category_name_3 == '' || recommend_goods_category_3 == 0){
		$("#recommend_goods_category_name_3").parent().children('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	return true;
}
</script>
{/block}